// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of DOM3XPath
//
// DOM3XPath is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// DOM3XPath is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with DOM3XPath. If not, see <http://www.gnu.org/licenses/>.
//	
//
//   $Id$
// XPathNSResolver.h : Declaration of the CXPathNSResolver

#ifndef __XPATHNSRESOLVER_H_
#define __XPATHNSRESOLVER_H_

#include "resource.h"       // main symbols
//#define COUNT_NSRESOLVER 1
/////////////////////////////////////////////////////////////////////////////
// CXPathNSResolver
class ATL_NO_VTABLE CXPathNSResolver : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CXPathNSResolver, &CLSID_XPathNSResolver>,
	public ISupportErrorInfo,
	public IDispatchImpl<IXPathNSResolver, &IID_IXPathNSResolver, &LIBID_DOM3XPATHLib, 1, 1>
{
		friend class CXPathEvaluator;
public:
	#ifdef COUNT_NSRESOLVER
		static unsigned long sm_Count;	
	#endif

	CXPathNSResolver():
	  m_sNamespaceCache(0)
	  {
		#ifdef COUNT_NSRESOLVER
			++sm_Count;	
		#endif

	}
	~CXPathNSResolver()
	{
		ATLTRACE("Destroying CXPathNSResolver\n");
		ATLTRACE("\tm_pNode - should be 1 (2 if corresponding Expression still alive.)\n");
		#ifdef COUNT_NSRESOLVER
			--sm_Count;	
		#endif

	}

DECLARE_REGISTRY_RESOURCEID(IDR_XPATHNSRESOLVER)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CXPathNSResolver)
	COM_INTERFACE_ENTRY(IXPathNSResolver)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

// IXPathNSResolver
public:
	STDMETHOD(lookupNamespaceURI)(BSTR prefix, BSTR * retVal);
private:
	CComQIPtr<IXMLDOMNode>m_pNode;
	//speeds up subsequent excecutions
	//	of getAllNamespaces()
	mutable CComBSTR m_sNamespaceCache;
public://not com
	HRESULT getAllNamespaces(BSTR* pResult) const;
	HRESULT initialise(IXMLDOMNode * pNode);
};

#endif //__XPATHNSRESOLVER_H_
